class JQRecordAmendService extends global.JQService {
	
    async do_action(){
		
		console.log('product create 33311111');
		if(!this.conn)console.log('do_action::conn error');
		let data_obj = this.req_obj.data_obj;
		let inst = global.JQTableIF.instance('record_table',this.conn);
		let inst_obj = global.JQTableIF.instance('object_table',this.conn);
		// let params = ['obj not like ','%my_value2":null%'];
		let params =null; //['id in',[69,70,71,72]];
		let list = await inst.query(['id','obj'],params,0,100,null,null);
		let ids =[];
		if(list && list.length>0){
			list.forEach((item)=>{
				let obj = JSON.parse(item.obj);
				
				if(obj.items){
					obj.items.forEach((it)=>{
						ids.push(it.id);
						
					})
				}
				item.obj=obj;
				console.log('list of newl 0000000 ' + JSON.stringify(list))
				
				// inst.update(item);
			})
			console.log('list of newl aaaaaa ' + JSON.stringify(list))
		}
		
		let objs=await inst_obj.query(['id','value','value_unit','divisor2_unit','divisor_unit'],['id in ',ids],0,10000,null);
		
		console.log('list of newl bbbbb ' + JSON.stringify(list))
		
		
		if(list && list.length>0){
			list.forEach((item)=>{
				let obj =item.obj;
				if(obj.items){
					obj.items.forEach((it)=>{
						let oo = null;
						for(let i =0;i<objs.length;i++){
							if(objs[i].id==it.id){
								oo =objs[i];
								break;
							}
						}
						if(oo){
							it.value=oo.value;
							it.value_unit =oo.value_unit;
							it.divisor_unit= oo.divisor_unit;
							it.divisor2_unit=oo.divisor2_unit;
						}
					})
				}
				item.obj=JSON.stringify(obj);

			})
			
		}
		console.log('list of newl' + JSON.stringify(list))
		
		for(let i =0;i<list.length;i++){
			console.log(JSON.stringify(list[i]));
			await inst.update(list[i]);
		}
		
		// let result = await inst.create(obj);	
		
		if(!list)return null;
		let wrap ={list:list};		
		return wrap;		
	}
	

}
module.exports = JQRecordAmendService;


